package main.ServerTest;

import main.Service.FriendshipService;
import main.ServiceImpli.FriendshipServiceImpl;
import main.dao.FriendshipDAO;
import main.pojo.Friendship;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class FriendshipServiceImplTest {
    private FriendshipService friendshipService;
    private FriendshipDAO friendshipDAO;

    @Before
    public void setUp() {
// 创建实际的FriendshipDAO对象
        friendshipService = new FriendshipServiceImpl();
    }

    @Test
    public void testGetFriendshipByID() {
        int friendshipID = 1;
        Friendship expectedFriendship = new Friendship();
        // 假设FriendshipDAO能够正确返回Friendship对象
        Friendship actualFriendship = friendshipService.getFriendshipByID(friendshipID);
        System.out.println(actualFriendship.toString());
        assertNotNull(actualFriendship);
//        assertEquals(expectedFriendship, actualFriendship);
    }

    @Test
    public void testGetFriendshipsByUser() {
        int userID = 2;
        List<Friendship> expectedFriendships = new ArrayList<>();
        // 假设FriendshipDAO能够正确返回Friendship列表
        List<Friendship> actualFriendships = friendshipService.getFriendshipsByUser(userID);
        System.out.println(actualFriendships.size());
        for (Friendship friendship:actualFriendships){
            System.out.println(friendship.toString());
        }
    }
    @Test
    public void testCreateFriendship() {
        Friendship friendship = new Friendship();
        // 假设FriendshipDAO能够成功创建Friendship对象
        friendship.setFriendshipID(72);
        friendship.setUserID(2);
        friendship.setFriendID(3);
        boolean result = friendshipService.createFriendship(friendship);
        System.out.println(result);
        assertTrue(result);
    }

    @Test
    public void testDeleteFriendship() {
        int friendshipID = 700;
        // 假设FriendshipDAO能够成功删除Friendship对象
        boolean result = friendshipService.deleteFriendship(friendshipID);
        assertTrue(result);
    }
}
